<?php 
if(!isset($no_render) || $no_render==false)
{
?>
<div class="eavFields form">
<?php echo $form->create('EntityField', array('url'=>'/'.$this->params['url']['url'],'id'=>'EntityFieldForm'));?>

	<fieldset>
 		<legend>Define Field</legend>
	<?php
		echo $form->input('EntityField.group');
		echo $form->input('EavField.name');
		echo $form->input('EavField.label');
		echo $form->input('EavField.type', array('onchange'=>'processEavType(this);'));
		echo $form->input('EavField.children', array('div'=>array('class'=>'hidden')));
		echo $form->input('EavField.required');
		//echo $form->input('validation');
		echo $form->input('EavField.value');
		echo $form->input('EavField.tooltip');
		echo $form->input('EavField.options',array('div'=>array('style'=>'display:none')));
	?>
		<a href="javascript:void();" onclick="return insertRange();">Insert numeric range</a>	
	<?php 
		//echo $form->input('EntityField.order');
	?>
	</fieldset>
<?php echo $form->end(__('Submit'));?>
</div>
<div class="actions">
	<ul>
		<li><?php echo $html->link(__('List EavFields', true), array('action'=>'index'));?></li>
		<li><?php echo $html->link(__('List Eav Values', true), array('controller'=> 'eav_values', 'action'=>'index')); ?> </li>
		<li><?php echo $html->link(__('New Eav Value', true), array('controller'=> 'eav_values', 'action'=>'add')); ?> </li>
	</ul>
</div>
<?php } ?>
<script>
$(document).ready(function(){
	processEavType();
	})
function processEavType()
{
	var typeWithOptions = ["select","multipleSelect","checkboxGroup","radio","multipleCheckbox"];
	if($.inArray($('#EavFieldType').val(),typeWithOptions) != -1)
	{
		$('#EavFieldOptions').closest('div').css('display','');
	}else
	{
		$('#EavFieldOptions').closest('div').css('display','none');
		checkIfParent();

	}

}
function checkIfParent()
{
	if($('#EavFieldType').val()=='parent')
	{
		$('#EavFieldChildren').parent().show('slow');
		$('#EavFieldChildren').parent().removeClass('hidden');
		return true;
	}
}

function insertRange()
{
	$('#EavFieldOptions').val("");
	var min = prompt("Enter lower limit", "");
	var max = prompt("Enter upper limit", "");
	var appendVal = "";

	var i;
	for(i=min; i<=max; i++)
	{
		appendVal = appendVal + "\n"+i;
	}
	$('#EavFieldOptions').val(appendVal);
	return false;
	
}
</script>